<?php

class UserHandler{

private $usearch;
private $cat;
private $con;

public function setUsearch($u){

$this->usearch=$u;
}

public function setCat($cats){

$this->cat=$cats;
}

public function setConnect($conn){

$this->con=$conn;

}



public function userAdd($emp,$username,$password,$level,$status){


$sql="insert into login (emp_reg,u_name,p_word,level,status) values('$emp','$username','$password','$level','$status')";

mysql_query($sql,$this->con) or 
die(mysql_error());

$msg="Succussfully Created";

return $msg;

}



public function getPageSearch($startrow,$limit){


$sql="select emp_reg,u_name,level,status from login order by u_name desc  Limit $startrow,$limit";

$result= mysql_query($sql,$this->con)or die(mysql_error()); 
return $result;
}



public function getSearch($startrow,$limit){ 

if($this->cat=="reg"){

$sql="select emp_reg,u_name,level,status from login where emp_reg ='$this->usearch' limit $startrow,$limit";

 }else{ 

$sql="select emp_reg,u_name,level,status from login where u_name like '$this->usearch%' limit $startrow,$limit";
}

$result= mysql_query($sql,$this->con)or die(mysql_error()); 
return $result;


}


public function getPaginationRow(){ 


if($this->cat=="reg"){

$sql="select emp_reg,u_name,level,status from login where emp_reg='$this->usearch' ";

} 

else {

$sql="select emp_reg,u_name,level,status from login where u_name like '$this->usearch%'";
}

$result= mysql_query($sql,$this->con)or die(mysql_error()); 
return $result;
}


public function getDelete($id){

$sql="DELETE FROM login WHERE u_name='$id'";
mysql_query($sql,$this->con);

$msgd="Deleted";
return $msgd;
}



public function userUpdate($id,$empno,$level,$status){
		
		
$sql="update login set emp_reg='$empno',level='$level' ,status='$status' where u_name='$id' "; 		
		
mysql_query($sql,$this->con) or 
die(mysql_error());

$msg =" Record Successfully updated";

return $msg;	
		
}

public function getLogPageSearch($startrow,$limit){


$sql="select u_name,date(log_date) as dats ,time(log_date) as times from history order by log_id desc Limit $startrow,$limit";

$result= mysql_query($sql,$this->con)or die(mysql_error()); 
return $result;
}


public function getLogPaginationRow(){ 

$sql="select u_name,date(log_date) as dats ,time(log_date) as times from history where u_name='$this->usearch' order by log_id desc ";
$result= mysql_query($sql,$this->con)or die(mysql_error()); 
return $result;
}

public function getLogSearch($startrow,$limit){


$sql="select u_name,date(log_date) as dats ,time(log_date) as times from history where u_name='$this->usearch' order by log_id desc Limit $startrow,$limit";

$result= mysql_query($sql,$this->con)or die(mysql_error()); 
return $result;
}


}

?>